package cn.bigfire.wedesk.action;

import cn.bigfire.wedesk.action.vo.WebInfo;
import cn.bigfire.wedesk.annotation.CMD;
import cn.bigfire.wedesk.bean.Wedesk;
import cn.bigfire.wedesk.net.protocol.Protocol;
import cn.bigfire.wedesk.store.Stores;
import cn.bigfire.wedesk.store.Threads;
import cn.bigfire.wedesk.util.AuthUtil;
import com.alibaba.fastjson.JSON;

import java.util.Map;

public class WebAction {



    @CMD(Wedesk.Cmd.CMD_WEB_INFO)
    public void webInfo(WebInfo webInfo) {
        webInfo.setCid(Threads.getChannelId());
        System.out.println("webInfo:" + JSON.toJSONString(webInfo));
    }

    @CMD(Wedesk.Cmd.CMD_ADMIN_AUTH)
    public void auth(String authStr) {
        System.out.println("authStr:" + JSON.toJSONString(authStr));
        if (AuthUtil.auth(authStr)) {//授权成功
            System.out.println("授权成功");
            Threads.getContext().send(Protocol.of(Wedesk.Cmd.CMD_ADMIN_AUTH, Stores.findAllPcInfos()));
        }else {//授权失败
            System.err.println("授权失败,client:" + authStr + ",server:" + AuthUtil.authStr());
            Threads.getContext().send(Protocol.err("授权失败"));
        }
    }

    @CMD(Wedesk.Cmd.CMD_CTRL_LIST)
    public void list() {
        Threads.getContext().send(Protocol.of(Wedesk.Cmd.CMD_CTRL_LIST,Stores.findAllPcInfos()));
    }


}
